/**
 * @Author Stringzhua
 * @Date 2024/5/31 12:31
 * description:
 */
import java.util.*;

class DFA {
    private Map<String, Map<Character, String>> transitions;
    private Set<String> finalStates;
    private String startState;

    public DFA(Map<String, Map<Character, String>> transitions, Set<String> finalStates, String startState) {
        this.transitions = transitions;
        this.finalStates = finalStates;
        this.startState = startState;
    }

    public boolean accepts(String input) {
        String currentState = startState;
        for (char c : input.toCharArray()) {
            if (!transitions.containsKey(currentState) || !transitions.get(currentState).containsKey(c)) {
                return false;
            }
            currentState = transitions.get(currentState).get(c);
        }
        return finalStates.contains(currentState);
    }
}

public class dfa_info {
    public static void main(String[] args) {
        // 定义DFA的转换表、终态集和初态
        Map<String, Map<Character, String>> transitions = new HashMap<>();
        transitions.put("s0", new HashMap<Character, String>() {{
            put('a', "s1");
            put('b', "s2");
        }});
        transitions.put("s1", new HashMap<Character, String>() {{
            put('a', "s2");
            put('b', "s1");
        }});
        transitions.put("s2", new HashMap<Character, String>() {{
            put('a', "s1");
            put('b', "s2");
        }});
        Set<String> finalStates = new HashSet<>(Arrays.asList("s1"));
        String startState = "s0";

        // 创建DFA实例
        DFA dfa = new DFA(transitions, finalStates, startState);

        // 测试输入字符串
//        String input = "abb";
        String input = "abab";
        System.out.println(dfa.accepts(input) ? "yes" : "no");
    }
}

